package com.github.raffle.behavior.visitor;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ConcreteVisitor implements Visitor {

	public static final String VISIT = "visit";
	
	@Override
	public void visit(Object obj) {
		String className = obj.getClass().getName();
		String methodName = VISIT + className.substring(className.lastIndexOf(".")+1);
		
		try {
			Method method = this.getClass().getMethod(methodName, new Class[]{obj.getClass()});
			method.invoke(this, new Object[]{obj});
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}

}
